home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
bplus20.zip
/
VTEST.C
< prev
Wrap
Text File
|
1989-02-13
|
3KB
|
104 lines
/* VTEST.C test program. */
/* This is a simple test program which creates two index files. */
/* 100 keys are added to each file, some keys are deleted and */
/* then the keys are added back to the file. The keys are listed */
/* in ascending and decending order. */
#include "bplus.h"
#include <stdio.h>
#include <time.h>
#include <conio.h>
/* extern bplus_network; */
IX_DESC name1, name2; /* index file variables */
void uplist(name) /* list keys in ascending order */
IX_DESC *name;
{
ENTRY ee;
first_key(name);
while (next_key(&ee, name) == IX_OK) printf("%s ",ee.key);
printf("\nPress any key to continue \n");
getch();
}
void downlist(name) /* list keys in decending order */
IX_DESC *name;
{
ENTRY ee;
last_key(name);
while (prev_key(&ee, name) == IX_OK) printf("%s ",ee.key);
printf("\nPress any key to continue \n");
getch();
}
main()
{
int i;
clock_t clock(void);
float stime, etime;
ENTRY e;
/* bplus_network = 0; */
printf("Make two index files\n");
make_index("test1.idx",&name1, 0);
make_index("test2.idx",&name2, 1);
printf("Indexing 100 items in two index files:\n");
/* note the time to index */
stime = clock();
/* add 100 keys to each index file */
for (i = 0; i < 100; i++)
{
e.recptr = (long) i;
sprintf(e.key, "VALUE1-%2d",i);
add_key(&e, &name1);
sprintf(e.key, "VALUE2-%2d",i);
add_key(&e, &name2);
}
/* print the time required for indexing the two files */
etime = clock();
printf("Indexing is complete. The time was %f\n\n", (etime - stime)/CLK_TCK);
printf("List the keys in each index file in ascending order:\n\n");
uplist(&name1);
uplist(&name2);
/* delete some keys and list again */
printf("\nNow delete all keys from 20 to 90 in each file\n\n");
for (i = 20; i < 90; i++)
{
e.recptr = (long) i;
sprintf(e.key, "VALUE1-%2d",i);
delete_key(&e, &name1);
sprintf(e.key, "VALUE2-%2d",i);
delete_key(&e, &name2);
}
printf("List the keys now for each index file in ascending order:\n\n");
uplist(&name1);
uplist(&name2);
/* add the keys back and list again */
printf("Now add back all items from 20 to 90 to each index\n\n");
for (i = 20; i < 90; i++)
{
e.recptr = (long) i;
sprintf(e.key, "VALUE1-%d",i);
add_key(&e, &name1);
sprintf(e.key, "VALUE2-%d",i);
add_key(&e, &name2);
}
printf("List the keys for each index file again in ascending order:\n\n");
uplist(&name1);
uplist(&name2);
/* list both files in decending order */
printf("List the keys for each index file in decending order\n\n");
downlist(&name1);
downlist(&name2);
/* always close all files */
close_index(&name1);
close_index(&name2);
}